package com.ksl.kinglockguard.domain;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class BannerList implements Serializable {
	private int mCount;
	private List<BannerNews> focusList = new ArrayList<BannerNews>();

	public int getBannerCount() {
		return mCount;
	}

	public List<BannerNews> getNewslist() {
		return focusList;
	}

	public static BannerList parse(JSONArray dataList) throws IOException,
			JSONException {
		BannerList mlist = new BannerList();
		if (null != dataList) {
			mlist.mCount = dataList.length();
			for (int i = 0; i < dataList.length(); i++) {
				JSONObject newsJson = dataList.getJSONObject(i);
				BannerNews news = new BannerNews();
				news.setId(newsJson.getInt("id"));
				news.setTitle(newsJson.getString("title"));
				news.setArticleUrl(newsJson.getString("link"));
				try{
					news.setImageUrl(newsJson.getString("img"));
				}catch(Exception e){
					e.printStackTrace();
				}
				mlist.focusList.add(news);
			}
			
		}
		return mlist;
	}
}
